package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.ParkDao;
import cn.topevery.garden.entity.po.Park;
import cn.topevery.garden.entity.query.ParkQuery;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.GeometryHelper;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-06
 */
@Service
public class ParkLogic extends BaseLogic<Park> {
    @Autowired
    ParkDao parkDao;

    @Autowired
    ParkFileLogic parkFileLogic;

    @Override
    public BaseEntityDao<Park, Integer> getDao() {
        return parkDao;
    }

    public List<Map<String,Object>> getShortList(){
        return parkDao.getShortList();
    }

    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<Park> listPage(ParkQuery query) {
        DataPager<Park> pager = parkDao.listPage(query);
        pager.records.forEach(park -> {
            if (park.geomWgs != null) {
                park.mapRangesPoints = GeometryHelper.getGeometryPoint(park.geomWgs);
                park.geomWgs = null;
            }
            park.fileList = parkFileLogic.getListByPid(park.id);
        });
        return pager;
    }

    public List<Park> getListBySectionId(List<Integer> ids) {
        return parkDao.getListBySectionId(ids);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        parkDao.delete(userId, ids);
    }

    public  boolean saveOrUpdate(String userId,Park entity){
        parkDao.saveOrUpdate(userId,entity);
        return true;
    }

    public Integer getParkIdByCodeAndName(String code, String name){
        return parkDao.getParkIdByCodeAndName(code, name);
    }

}
